#include<iostream>
#include<cstdio>
#include<vector>
#define MAXN 50001 
using namespace std;
class nodes{
	public:
		int min,max,f,t;
}node[MAXN];
vector<int>out;
int n,q,t[MAXN],nn=1;
inline int read(){
    int k=0;char f=1,c=getchar();
    for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
    for(;isdigit(c);c=getchar())k=k*10+c-'0';
    return k*f;
}
void find(int i,int be,int en){
	int left=i*2,right=i*2+1;
	if(node[i].f>=be&&node[i].t<=en){
		out.push_back(i);
		return;
	}else if(left<=n){
		if(be<=node[left].t){
			if(en<=node[left].t)find(left,be,en);
			else find(left,be,node[left].t);
		}
		if(right<=n&&node[right].f<=en)find(right,node[right].f,en);
	}
}
void creat(){
	node[1].f=1;
	node[1].t=n;
	for(nn=1;;nn++){
		if(node[nn].f==node[nn].t)break;
		int mid=(node[nn].f+node[nn].t)/2;
		node[nn*2].f=node[nn].f;
		node[nn*2].t=mid;
		node[nn*2+1].f=mid+1;
		node[nn*2+1].t=node[nn].t;
	}
	for(int i=nn*2+1,j=1;j<=n;i--){
		if(node[i].t==node[i].f){
			j++;
			node[i].min=node[i].max=t[node[i].f];
		}
	}
	for(int i=nn+1;i>=1;i--){
		if(node[i*2+1].f){
			int mi=min(node[i*2].min,node[i*2+1].min);
			int mx=max(node[i*2].max,node[i*2+1].max);
			node[i].min=min(node[i].min,mi);
			node[i].max=max(node[i].max,mx);
		}else{
			node[i].min=node[i*2].min;
			node[i].max=node[i*2].max;
		}
	}
}
int main(){
	//freopen("2.txt","r",stdin);
	n=read();q=read();
	for(int i=1;i<=n;i++){
		scanf("%d",&t[i]);
		node[i].min=t[i];
		node[i].max=t[i];
	}
	creat();
	
	while(q--){
		int begin=read(),end=read();
		find(1,begin,end);
		int in=0xffffff,ax=0;
		for(int k=0;k<out.size();k++){
			in=min(in,node[out[k]].min);
			ax=max(ax,node[out[k]].max);
		}
		printf("%d",ax-in);
		
		printf("\n");
		for(int k=0;k<out.size();k++)printf("%d ",out[k]);
		printf("\n");
		out.clear();
	}
	for(int j=1,i=1;i<=n;i++){
		cout<<t[i]<<" ";
		if(i==j){
			j=1+j*2;
			cout<<endl;
		}
	}
	cout<<endl;
	for(int j=1,i=1;i<=nn*2;i++){
		printf("%d : from : %d to : %d min : %d max : %d \n",i,node[i].f,node[i].t,node[i].min,node[i].max);
	}
}
